<template>
    <div class="calendar">
        <div class="search-box">
            <el-form inline>
                <el-form-item label="日期">
                    <div class="space">
                        <el-date-picker v-model="paramsForm.startTime" type="month" placeholder="请选择" value-format="YYYY-MM"/>
                        -
                        <el-date-picker v-model="paramsForm.endTime" type="month" placeholder="请选择" value-format="YYYY-MM"/>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="init">查询</el-button>
                    <el-button type="primary" @click="reset">重置</el-button>
                    <el-button type="primary" @click="visible = true">同步</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-table :data="data">
            <el-table-column label="日期" prop="holidayDate">
                <template #default="scope">
                    {{ scope.row.holidayDate.split(' ')[0] }}
                </template>
            </el-table-column>
            <el-table-column label="日期类型">
                <template #default="scope">
                    {{ type[scope.row.holidayType] }}
                </template>
            </el-table-column>
            <el-table-column label="周几" prop="holidayWeek"></el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination v-model:current-page="paramsForm.page" v-model:page-size="paramsForm.size"
                :page-sizes="[10, 20, 100, 200]" layout="total, sizes, prev, pager, next, jumper" :total="total"
                @change="init" />
        </div>
        <el-dialog v-model="visible" modal-class="add" width="400" align-center center :show-close="false" @close="synDate=''">
            <el-form label="同步年月">
                <el-input v-model="synDate" />
                <span>输入2024类似格式</span>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="visible = false">取消</el-button>
                    <el-button type="primary" @click="sync">
                        同步
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup>
import { onMounted } from "vue";
import { getList, syncData } from "@/api/system/calendar";
const visible = ref(false);
const paramsForm = ref({
    size: 10,
    page: 1
})
const type = ['工作日', '节假日', '双休日', '补班日']
const total = ref(0)
const data = ref([]);
const synDate = ref('')
const init = async () => {
    const res = await getList(paramsForm.value);
    data.value = res.data.records;
    total.value = res.data.total;
}
const reset = () => {
    paramsForm.value = {
        size: 10,
        page: 1
    };
    init()
}
const sync = async () => {
    await syncData({
        synDate: synDate.value
    });
    init();
    visible.value = false;
}
onMounted(() => {
    init()
})
</script>

<style lang="scss" scoped>
.calendar {
    padding: 20px;

    .space {
        display: flex;
        gap: 10px;
    }

    .dialog-footer {
        margin-top: 40px;
    }

    .pagination {
        display: flex;
        justify-content: end;
        margin-top: 20px;
    }

    span {
        font-size: 12px;
        color: rgb(117, 117, 117);
    }
}
</style>